package com.ysqcould.allocation.utils;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

/**
 * multipartFile文件处理类
 * @author Administrator
 */
public class MultipartFileUtils {
    public static JSONObject getFilePath(MultipartFile file) throws IOException {
        final String fileName = file.getOriginalFilename();
        final String uuId = UUID.randomUUID().toString().replace("-", "");
        final String s = fileName.substring(0, fileName.indexOf("."));
        final String neFileName = fileName.replace(s, uuId);
        final InputStream in = file.getInputStream();
        final long millis = System.currentTimeMillis();
        String filePath=millis+"/"+neFileName;
        JSONObject json=new JSONObject();
        json.put("name",filePath);
        json.put("in",in);
        return json;
    }
}
